1 00:00:00,630 --> 00:00:04,590 Now let's take a look at Chuck Norris move and PC script. 2 00:00:04,590 --> 00:00:11,550 So we put the kick in him on there and we have the ID, so we'll go to move and pick on Chuck Norris. 3 00:00:11,580 --> 00:00:12,780 Open it up. 4 00:00:12,930 --> 00:00:18,600 And then I'm going to close this animation editor so that I have more room to scroll to the top. 5 00:00:18,600 --> 00:00:22,860 I'm already at the top, and we're going to have to add some variables. 6 00:00:23,730 --> 00:00:27,630 We're going to need a variable for our front kick animation. 7 00:00:27,630 --> 00:00:35,190 So I'll say local front kick and M, and that's on the script, right? 8 00:00:35,190 --> 00:00:43,020 So equals we'll do script colon, wait for child kick in. 9 00:00:43,020 --> 00:00:47,270 M And what else we're going to need an animator. 10 00:00:47,280 --> 00:00:53,790 Make sure Chuck Norris is humanoid has an animator let's go ahead and click on that mine does. 11 00:00:53,790 --> 00:00:58,410 If it does not hit the plus sign hit a add an animator. 12 00:00:58,710 --> 00:01:13,470 Sometimes they don't, but mine has one so good local animator we'll do r i NPC that's Chuck Norris, 13 00:01:13,500 --> 00:01:13,890 right? 14 00:01:13,890 --> 00:01:15,630 Or script parent will work too. 15 00:01:15,630 --> 00:01:19,500 That'll get you the i NPC and we've got a humanoid. 16 00:01:19,500 --> 00:01:19,980 Oh, look at that. 17 00:01:19,980 --> 00:01:21,510 We already have the humanoid actually. 18 00:01:21,510 --> 00:01:25,560 So I whom I forgot we got him up here. 19 00:01:26,190 --> 00:01:30,720 Let's do a colon wait for child animator. 20 00:01:30,990 --> 00:01:32,520 Nice. 21 00:01:32,880 --> 00:01:35,160 And what else we're going to need. 22 00:01:37,020 --> 00:01:40,170 We're going to need a front kick track. 23 00:01:40,170 --> 00:01:54,000 So I'll say local front kick track and I will get that when I take my animator colon, do a load animation 24 00:01:54,030 --> 00:01:59,360 and put the front kick and am in the in the animator, which is in the humanoid. 25 00:01:59,370 --> 00:02:03,420 I'm going to get my track back and I'm going to be able to play that track. 26 00:02:04,780 --> 00:02:07,120 We're going to need a sound to. 27 00:02:07,480 --> 00:02:10,140 Let's get the kick working before we get the sound. 28 00:02:10,150 --> 00:02:12,780 But I will put a variable for the sound. 29 00:02:12,790 --> 00:02:15,670 I'll say kick sound. 30 00:02:15,670 --> 00:02:18,190 We might want to make it a general hit sound. 31 00:02:18,250 --> 00:02:19,990 Just make that nil for now. 32 00:02:20,260 --> 00:02:22,600 All right, now we're going to scroll down. 33 00:02:23,430 --> 00:02:25,470 To where we do our while loop. 34 00:02:25,470 --> 00:02:31,590 And this was the loop that we used for Cletus to find the nearest character and then get really close 35 00:02:31,590 --> 00:02:33,270 to them and follow them around. 36 00:02:33,270 --> 00:02:34,500 So we're going to keep that. 37 00:02:34,500 --> 00:02:35,250 We're going to keep that. 38 00:02:35,250 --> 00:02:36,300 We're going to add to it. 39 00:02:36,300 --> 00:02:41,220 Before I add to it, I'm going to make another helper function above that while loop. 40 00:02:41,610 --> 00:02:48,510 Let's say a local function I'm going to call that is within range. 41 00:02:48,510 --> 00:02:49,770 So I want to know. 42 00:02:49,770 --> 00:02:55,740 And Chuck considers himself close enough to do a CEC, or we might want to use this for other things. 43 00:02:55,740 --> 00:02:57,390 So I'm going to keep it kind of general. 44 00:02:57,510 --> 00:03:00,960 The HRP is going to be Chuck's humanoid root part. 45 00:03:00,960 --> 00:03:02,370 The goal? 46 00:03:03,390 --> 00:03:07,380 Well, for our first application, at least, it's going to be the humanoid root part that he wants 47 00:03:07,380 --> 00:03:08,310 to kick. 48 00:03:08,340 --> 00:03:10,290 It'll be a part regardless. 49 00:03:10,450 --> 00:03:10,880 Whoops. 50 00:03:10,890 --> 00:03:11,670 Goal. 51 00:03:11,670 --> 00:03:12,810 And then a comma. 52 00:03:12,810 --> 00:03:14,940 And then I'm going to need a tolerance. 53 00:03:14,940 --> 00:03:17,040 How close is close? 54 00:03:17,040 --> 00:03:20,220 Enough so that he reached his goal? 55 00:03:20,220 --> 00:03:23,250 Like, is he within the range that we want? 56 00:03:23,250 --> 00:03:30,330 And I will just return a calculation and it's going to return the answer of the calculation. 57 00:03:30,330 --> 00:03:36,720 So I'm going to put it inside parentheses to get the humanoid root parts position of chalk. 58 00:03:36,840 --> 00:03:45,270 I'm going to subtract the goal position, probably the enemy humanoid root part. 59 00:03:45,360 --> 00:03:51,660 I'll do this dot mag magnitude, which I always spell wrong. 60 00:03:51,660 --> 00:03:59,700 And if it's less than our tolerance, we're going to assume, hey, he's close enough to kick them and 61 00:03:59,700 --> 00:04:06,150 maybe we'll put this whole thing in parentheses so that you could see that you're returning one single 62 00:04:06,150 --> 00:04:06,930 value. 63 00:04:06,930 --> 00:04:08,940 It's going to be a true or a false. 64 00:04:08,940 --> 00:04:11,490 So we're going to do this calculation. 65 00:04:12,190 --> 00:04:13,150 Right here. 66 00:04:13,150 --> 00:04:17,240 We're going to subtract the HRP from the or the goal from the HRP. 67 00:04:17,260 --> 00:04:20,230 We're going to take the magnitude, which is going to be the distance. 68 00:04:20,920 --> 00:04:27,550 And then we are going to see if it's less than a tolerance, which is a scalar number. 69 00:04:27,550 --> 00:04:29,590 We've got to set that tolerance, though. 70 00:04:29,590 --> 00:04:32,880 And if it is, we're close enough, It's going to be true. 71 00:04:32,890 --> 00:04:34,160 We're going to return true. 72 00:04:34,180 --> 00:04:34,630 Boom. 73 00:04:34,630 --> 00:04:36,030 We're going to do a kick. 74 00:04:36,040 --> 00:04:37,840 Let's go to the top here. 75 00:04:39,060 --> 00:04:46,650 And we'll do variable local, let's say, tall for kicks. 76 00:04:46,650 --> 00:04:48,280 So that's going to be my kick tolerance. 77 00:04:48,300 --> 00:04:50,570 How close do we have to be to the character to do it? 78 00:04:50,580 --> 00:04:52,440 Kick five. 79 00:04:52,440 --> 00:04:54,000 I'll say five studs away. 80 00:04:55,460 --> 00:04:55,730 All right. 81 00:04:55,730 --> 00:04:57,260 They're down here now. 82 00:04:57,530 --> 00:05:03,290 We're chasing them around with this move to let's see when he's within range. 83 00:05:03,290 --> 00:05:08,850 So I'll do local R and G. 84 00:05:08,870 --> 00:05:09,260 I'll keep it. 85 00:05:09,260 --> 00:05:15,650 A very simple variable is going to be local to the loop, and we'll have equal is within range. 86 00:05:15,650 --> 00:05:19,960 We're going to have our i hrp, which is Chuck's humanoid root part. 87 00:05:19,970 --> 00:05:23,740 We're going to have our closest humanoid root part. 88 00:05:23,750 --> 00:05:24,830 That's the goal. 89 00:05:24,830 --> 00:05:26,480 And then we're going to have our tolerance. 90 00:05:26,480 --> 00:05:29,690 We call that what tall for kick cool. 91 00:05:29,690 --> 00:05:32,270 And also remember we're going to be doing damage, right? 92 00:05:32,270 --> 00:05:33,500 We're not just following around. 93 00:05:33,500 --> 00:05:35,720 We're going to be we're going to be kicking them and hurting them. 94 00:05:35,720 --> 00:05:38,630 So we really need the humanoid root part. 95 00:05:38,630 --> 00:05:42,440 Also, let's get that local. 96 00:05:42,440 --> 00:05:47,360 We have the closest HRP Let's get the closest. 97 00:05:47,600 --> 00:05:50,670 HUME Using the closest air. 98 00:05:50,720 --> 00:05:56,570 P So do closest air parent that's going to give us the character of the humanoid root part that we're 99 00:05:56,570 --> 00:05:57,350 close to. 100 00:05:57,380 --> 00:06:01,520 We'll do a colon, find first child humanoid. 101 00:06:02,300 --> 00:06:04,350 All right, now let's do an if statement. 102 00:06:04,370 --> 00:06:09,800 So we'll say if we are within range, right? 103 00:06:09,800 --> 00:06:13,910 And let's make sure the closest humanoid root part exists. 104 00:06:13,910 --> 00:06:15,650 He's not responding or something, right? 105 00:06:15,650 --> 00:06:16,310 He just died. 106 00:06:16,310 --> 00:06:18,080 Now the humanoid root parts gone. 107 00:06:18,380 --> 00:06:25,940 And we'll also check to see if the closest humanoid root parts health is greater than zero. 108 00:06:25,940 --> 00:06:31,310 So it's here and it's also there are some health here. 109 00:06:31,310 --> 00:06:31,940 He's gone. 110 00:06:31,940 --> 00:06:36,500 He might be like responding halfway through the humanoid root parts there, but the humanoid is not 111 00:06:36,500 --> 00:06:39,800 something crazy like that, just being extra special. 112 00:06:39,800 --> 00:06:40,550 Careful. 113 00:06:40,550 --> 00:06:45,830 And then if all those conditions are true, we can go ahead and do our kick. 114 00:06:45,830 --> 00:06:49,340 So we have our kick, not kick sound. 115 00:06:49,340 --> 00:06:52,370 We have our kick front kick track. 116 00:06:52,370 --> 00:06:53,450 That's what we want. 117 00:06:53,600 --> 00:06:55,070 Front, kick, track. 118 00:06:55,070 --> 00:06:58,790 Cole And play. 119 00:07:00,810 --> 00:07:06,330 And since we're doing a kick and we're close, let's go ahead and give him credit for damage. 120 00:07:06,330 --> 00:07:13,890 So do closest HR P No close is humanoid colon Take damage. 121 00:07:14,040 --> 00:07:16,470 Take damage. 122 00:07:16,470 --> 00:07:18,270 Let's make it like 30. 123 00:07:18,270 --> 00:07:21,750 Oh, let's put a variable in there for for the damage, for the kick. 124 00:07:21,750 --> 00:07:22,680 Let's do that. 125 00:07:22,680 --> 00:07:24,060 Let's go up to the top. 126 00:07:25,220 --> 00:07:33,800 Where we declare our variables and we'll have kick damage, local kick damage equals 30, and then we'll 127 00:07:33,800 --> 00:07:35,960 just put that variable down here. 128 00:07:35,960 --> 00:07:40,460 It'll be a little easier to find if you're updating your code and digging around and code. 129 00:07:40,460 --> 00:07:40,820 Right. 130 00:07:40,820 --> 00:07:43,850 So have kick damage, boom. 131 00:07:44,060 --> 00:07:47,060 So we have two small adjustments to make. 132 00:07:47,060 --> 00:07:48,620 One will do right now. 133 00:07:48,620 --> 00:07:55,760 When we made Cletus move to the person that he's following around, we stayed back five studs. 134 00:07:55,760 --> 00:07:59,330 But our tolerance for kick is five studs. 135 00:07:59,330 --> 00:08:03,800 So I'm going to change this to two studs. 136 00:08:03,800 --> 00:08:08,210 So when we move to, we're going to try and get two studs away from the person we're following. 137 00:08:08,210 --> 00:08:11,720 Well, Chuck Norris is going to stop two studs away. 138 00:08:11,720 --> 00:08:14,960 That's going to give us three studs where we could fire off the kick. 139 00:08:15,110 --> 00:08:22,430 Another problem that we're having currently but might not exist when you watch this video is the closest 140 00:08:22,430 --> 00:08:27,980 humanoid dot health when the player dies doesn't quite go down to zero. 141 00:08:27,980 --> 00:08:30,320 It was some update they did recently. 142 00:08:30,320 --> 00:08:32,210 It's like one point something. 143 00:08:32,210 --> 00:08:37,790 Let's just go ahead and do a printout so we could see what that health is. 144 00:08:37,790 --> 00:08:39,140 There is a workaround. 145 00:08:39,140 --> 00:08:43,160 It's a shame we have to do it, but sometimes you have to do that in coding. 146 00:08:43,160 --> 00:08:53,270 Let's get our human health and we'll do closest humanoid dot health. 147 00:08:53,270 --> 00:08:58,430 So let's see what the health is because he's going to keep kicking and charting is going to keep kicking 148 00:08:58,430 --> 00:08:59,780 even though we died. 149 00:09:00,500 --> 00:09:05,960 Let's go to our NPC work and move our spawn location a little closer. 150 00:09:05,960 --> 00:09:08,360 This is the chuck that I showed in the demo. 151 00:09:08,390 --> 00:09:14,120 This is the Chuck Norris that we are working on now, so I want to be closer to him. 152 00:09:14,390 --> 00:09:15,470 Let's hit the play. 153 00:09:17,410 --> 00:09:22,010 Now we're going to have our invincibility bubble up for a little bit. 154 00:09:22,030 --> 00:09:24,280 This little haze goes around. 155 00:09:24,370 --> 00:09:27,340 So you won't take any any damage right away. 156 00:09:27,760 --> 00:09:29,860 Let's go to our view. 157 00:09:31,000 --> 00:09:34,080 That output window get closed. 158 00:09:34,100 --> 00:09:34,600 There we go. 159 00:09:34,610 --> 00:09:35,860 Now we can get some damage. 160 00:09:35,870 --> 00:09:38,090 Boom, boom, boom. 161 00:09:38,120 --> 00:09:39,470 See the house going down? 162 00:09:39,470 --> 00:09:41,020 Went down at 13. 163 00:09:41,030 --> 00:09:43,730 Oh, and he's still kicking, so. 164 00:09:44,090 --> 00:09:47,030 And then we could see that the health was one and one. 165 00:09:47,180 --> 00:09:54,680 I was going to do the diet event check for the diet event in the character that had the closest humanoid 166 00:09:54,680 --> 00:09:55,640 root part. 167 00:09:55,640 --> 00:10:02,330 But, you know, we have to still put the the force on where it kicks them back and it's probably going 168 00:10:02,330 --> 00:10:04,880 to kick them back far enough where it's not going to be an issue. 169 00:10:04,880 --> 00:10:11,660 So I think I'm just going to go with that and we'll monitor the health less than zero to see if it gets 170 00:10:11,660 --> 00:10:13,220 fixed in the next update. 171 00:10:13,220 --> 00:10:17,780 We also have to put a sound on the kick to make it sound cool. 172 00:10:17,780 --> 00:10:21,440 So in the next video, let's go ahead and get started on those other things.